package itheima01;

import java.io.*;

/**
 * @author xxx
 * @date 2020/12/24 2:51
 * @description
 */
public class Test {
    public static void main(String[] args) throws IOException {
        //通过写入对应编码内容，以该文件对应的编码读取该文件内容，遍历展示出来day13\gbkfile.txt和day13/gbkfile.txt

               lr();
               dx();
    }

    public static  void  lr() throws IOException {
        OutputStreamWriter outputStreamWriter=new OutputStreamWriter(new FileOutputStream("day13\\gbkfile.txt"),"GBK");
        outputStreamWriter.write("吃饭222睡觉");
        outputStreamWriter.write("\r\n");
        outputStreamWriter.write(100);
        outputStreamWriter.close();

        OutputStreamWriter outputStreamWriter1=new OutputStreamWriter(new FileOutputStream("D:\\java349\\day13\\utf8file.txt"),"UTF-8");
        outputStreamWriter1.write("吃饭睡111觉");
        outputStreamWriter1.write("\r\n");
        outputStreamWriter1.write(100);
        outputStreamWriter1.close();
    }

    public  static  void  dx() throws IOException {
        InputStreamReader inputStreamReader=new InputStreamReader( new FileInputStream("D:\\java349\\day13\\gbkfile.txt"),"GBK");
        char[] chars=new char[1024];
        int  t=0;
        while ((t=inputStreamReader.read(chars))!=-1){
            System.out.println(new String(chars,0,t));
        }
        inputStreamReader.close();


        InputStreamReader inputStreamReader1=new InputStreamReader( new FileInputStream("day13/utf8file.txt"),"UTF-8");
        char[] chars1=new char[1024];
        int  tt=0;
        while ((tt=inputStreamReader1.read(chars1))!=-1){
            System.out.println(new String(chars1,0,tt));
        }
        inputStreamReader1.close();


    }
}
